package com.fzy.core;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

public class ValidationResultInterceptor extends MethodFilterInterceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = -700264481455611525L;
	private static final Log _log = LogFactory.getLog(ValidationResultInterceptor.class);

	protected String doIntercept(ActionInvocation invocation) throws Exception {
		Object action = invocation.getAction();

		if (action instanceof MyValidationAware) {
			MyValidationAware validationAwareAction = (MyValidationAware) action;

			if (validationAwareAction.hasErrors()) {
				if (_log.isDebugEnabled()) {
					_log.debug("Errors on action " + validationAwareAction
							+ ", returning result name 'input'");
				}
				return validationAwareAction.getErrorDispatch();
			}
		}
		return invocation.invoke();
	}
}
